<!---
	required pre-set parameters:
		* eform.sender
		* eform.tablename
		* eform.field

	optional parameters:
		* eform.addnew
		* eform.char
		* eform.locator
--->

<!--- Set the number of records to display on each page. --->
<CFIF NOT IsDefined("nOnEachPage")>
	<CFSET OnEachPage = 10>
<CFELSE>
	<CFSET OnEachPage = nOnEachPage>
</CFIF>

<!--- first --->
<CFIF isDefined("Form.First")>
	<CFSET form.startrow = 1>
</CFIF>

<CFIF	isDefined("Form.Prior")>
	<CFSET form.startrow = (form.startrow - OnEachPage)>
</CFIF>

<CFIF	isDefined("Form.Next")>
	<CFSET form.startrow = (form.startrow + OnEachPage)>
</CFIF>

<CFIF	isDefined("Form.Last")>
	<CFSET form.startrow = (GetData.RecordCount - (GetData.RecordCount MOD OnEachPage)) + 1>
	<CFIF  form.startrow GT GetData.RecordCount>
		<CFSET form.startrow = (GetData.RecordCount - OnEachPage) + 1>
	</CFIF>
</CFIF>



<!--- get the last rows to be displayed --->
<CFSET LastRow = (GetData.RecordCount - (GetData.RecordCount MOD OnEachPage)) + 1>
<CFIF LastRow GT GetData.RecordCount>
	<CFSET LastRow = (GetData.RecordCount - OnEachPage) + 1>
</CFIF>

<!--- Set the value of endrow to the maxrows + startrow - 1 --->
<CFSET EndRow = form.startrow + OnEachPage - 1>

<!--- If the end row is greater than the recordcount, determine how many records are left. --->
<CFIF EndRow GTE GetData.RecordCount>
	<CFSET EndRow = GetData.RecordCount>
	<CFSET Next = false>

<!--- Othereise, set Next to true and determine the next set of records. --->
<CFELSE>
	<CFSET Next = true>
	<CFIF EndRow + OnEachPage GT GetData.RecordCount>
		<CFSET NextNum = GetData.RecordCount - EndRow>
	<CFELSE>
		<CFSET NextNum =  OnEachPage>
	</CFIF>
	<CFSET NextStart = EndRow + 1>
</CFIF>

<!--- If StartRow is 1, set Previous to false. --->
<CFIF form.startrow IS 1>
	<CFSET Previous = false>

<!--- Othewise, determine the previous set of records. --->
<CFELSE>
	<CFSET Previous = true>
	<CFSET PreviousStart = form.startrow - OnEachPage>
</CFIF>
<!--- Create custom function for left mssql statement, work around for oracle and other db w/o left statement.
Note: first workaround is to use substring function but this does not work on date fields,
thus resulting to custom left function--->
<CFMODULE TEMPLATE="#client.common_path#cfm_sqlleftfunc.cfm" field="#eform.field#" numchars=1>
<CFSET sSQL = sqlstmt>
<!--- extract all unique items --->
<CFQUERY name="GetFirst" datasource="#table_dsn#">
	SELECT DISTINCT #sSQL# AS FIRSTCHAR
	FROM #eform.tablename#
	WHERE (PERSONNELIDNO = '#GetEmployee.PERSONNELIDNO#')
	ORDER BY FIRSTCHAR
</CFQUERY>

<CFOUTPUT>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=3 BGCOLOR="#client.color_grphead#" WIDTH="100%">
</CFOUTPUT>

	<TR>
		<CFOUTPUT>
		<TD NOWRAP><INPUT TYPE="hidden" NAME="StartRow" VALUE="#form.startrow#">
			&nbsp;
			<CFIF lcase(accessAdd) EQ "y">
				<INPUT TYPE="submit" NAME="Add" VALUE="Add" TITLE="Add new record" CLASS="bitbtn">
			</CFIF>
			&nbsp;
			<CFIF Previous>
				<INPUT TYPE="submit" CLASS="bitbtn" NAME="First" VALUE="&nbsp;|<&nbsp;" TITLE="First Recordset">
				<INPUT TYPE="submit" CLASS="bitbtn" NAME="Prior" VALUE="&nbsp;<&nbsp;" TITLE="Previous Recordset">
			<CFELSE>
				<INPUT DISABLED TYPE="submit" NAME="First" VALUE="&nbsp;|<&nbsp;" CLASS="bitbtn">
				<INPUT DISABLED TYPE="submit" NAME="Prior" VALUE="&nbsp;<&nbsp;" CLASS="bitbtn">
			</CFIF>
			<CFIF Next>
				<INPUT TYPE="submit" CLASS="bitbtn" NAME="Next" VALUE="&nbsp;>&nbsp;" TITLE="Next Recordset">
				<INPUT TYPE="submit" CLASS="bitbtn" NAME="Last" VALUE="&nbsp;>|&nbsp;" TITLE="Last Recordset">
			<CFELSE>
				<INPUT DISABLED TYPE="submit" NAME="Next" VALUE="&nbsp;>&nbsp;" CLASS="bitbtn">
				<INPUT DISABLED TYPE="submit" NAME="Last" VALUE="&nbsp;>|&nbsp;" CLASS="bitbtn">
			</CFIF>
			&nbsp;
			<INPUT TYPE="submit" NAME="Refresh" VALUE="Refresh" CLASS="bitbtn">
			<CFIF NOT ISDEFINED("url.batch")>
				<CFIF GETFORM.ENABLEGROUPROUTE EQ "Y" AND GETFORM.PROCESSCODE NEQ "">
					<INPUT TYPE="submit" NAME="brnGrpRoute" VALUE="Group Route" CLASS="bitbtn" onclick="UpdateGrpRoute()" <CFIF GetNotRouted.RECORDCOUNT LT 2> DISABLED </CFIF>>
				</CFIF>
				<CFIF GETFORM.ENABLEBATCHAPPLY EQ "Y" AND GETFORM.PROCESSCODE NEQ "" AND accessBatchApp EQ "Y">
					<CFQUERY NAME="GetBatchExist" DATASOURCE="#client.company_dsn#">
						SELECT FLDDATES
						FROM ECRGBATCHAPPLY
						WHERE BATCHID= '#GETFORM.FORMCODE#'
					</CFQUERY>
					<INPUT TYPE="submit" NAME="btnBatch" VALUE="Batch Apply" CLASS="bitbtn" onclick="BatchApply()" <CFIF NOT GetBatchExist.RECORDCOUNT>DISABLED</CFIF>>
				</CFIF>
			</CFIF>
		</TD>
		</CFOUTPUT>
		<TD WIDTH="100%"></TD>

		<!--- for sorting records --->
		<CFOUTPUT>
		<TD NOWRAP ALIGN="right" CLASS="white">
			&nbsp;Sort:&nbsp;
			<SELECT NAME="cmbSort" SIZE="1" CLASS="bitbtn">
				<CFLOOP INDEX="x" FROM=1 TO=#arraylen(eform.fieldsarray)#>
					<CFIF eform.field IS "#eform.fieldsarray[x][1]#">
						<OPTION SELECTED VALUE="#eform.fieldsarray[x][1]#">&nbsp;#eform.fieldsarray[x][2]#</OPTION>
					<CFELSE>
						<OPTION VALUE="#eform.fieldsarray[x][1]#">&nbsp;#eform.fieldsarray[x][2]#</OPTION>
					</CFIF>
				</CFLOOP>
			</SELECT>
			<select name="selAscDesc" class="bitbtn">
				<option selected value="asc">Ascending
				<option <CFIF eform.ascdesc IS "desc">selected</CFIF> value="desc">Descending
			</select>
			<INPUT TYPE="submit" TITLE="Sort Now" VALUE="Sort" NAME="Sort" CLASS="bitbtn">&nbsp;
			</CFOUTPUT>

			<!--- for filtering records --->
			&nbsp;Filter:&nbsp;
			<SELECT NAME="cmbFilter" SIZE="1" CLASS="bitbtn">
				<CFIF eform.char EQ "">
					<OPTION SELECTED VALUE="all">&nbsp;All Items&nbsp;</OPTION>
				<CFELSE>
					<OPTION SELECTED VALUE="all">&nbsp;All Items&nbsp;</OPTION>
				</CFIF>

				<CFOUTPUT QUERY="GetFirst">
					<CFIF eform.char IS "#FIRSTCHAR#">
						<OPTION VALUE="#FIRSTCHAR#" SELECTED>&nbsp;#ucase(FIRSTCHAR)#</OPTION>
					<CFELSE>
						<OPTION VALUE="#FIRSTCHAR#">&nbsp;#ucase(FIRSTCHAR)#</OPTION>
					</CFIF>
				</CFOUTPUT>
			</SELECT>

			<CFOUTPUT>
			<INPUT TYPE="text" NAME="edtValFilter" SIZE="8" CLASS="toolbar" VALUE="#eform.locator#">
			<INPUT TYPE="submit" TITLE="Apply Filter" NAME="Filter" CLASS="bitbtn" VALUE="Filter">&nbsp;
			</CFOUTPUT>
		</TD>
	</TR>
</TABLE>
